package com.netease.xone.adapter;

import android.graphics.drawable.ColorDrawable;
import android.support.v4.view.PagerAdapter;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.GridView;

import com.netease.xone.R;
import com.netease.xone.dataMgr.EmoticonMgr1;
import com.netease.xone.widget.ViewPagerChild;
import com.netease.xone.widget.ViewPagerChild.onEmoticonClickListener;
import com.netease.xone.widget.ViewPagerChild.onEmoticonTouchListener;


public class AdapterPagerEmoticon extends PagerAdapter {
    /** 表情View被Click的监听 */
    private onEmoticonClickListener mListener;
    /** 表情View被Touch的监听 */
    private onEmoticonTouchListener mOnEmoticonTouchListener;

    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        ViewPagerChild child = null;
        child = new ViewPagerChild(container.getContext());
        if (null != child) {
            child.setColumnWidth(container.getContext().getResources().getDimensionPixelSize(R.dimen.discuss_size_56));
            child.setFocusable(false);
            child.setGravity(Gravity.CENTER);
            child.setSelector(new ColorDrawable(0));
            child.setNumColumns(GridView.AUTO_FIT);
            child.setStretchMode(GridView.STRETCH_COLUMN_WIDTH);
            
            child.setCurrentEmoticon(EmoticonMgr1.getEmoticonList(position));
            child.setOnEmoticonClickListener(mListener);
            child.setOnEmoticonTouchListener(mOnEmoticonTouchListener);
            container.addView(child, 0);
        }
        return child;
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        container.removeView((View)object);
    }

    @Override
    public int getCount() {
        return 3;
    }

    @Override
    public boolean isViewFromObject(View arg0, Object arg1) {
        if (arg0 == arg1) {
            return true;
        }
        return false;
    }
    
    /**
     * 设置表情View被Click的监听。<br>
     * Click和Touch的区别，见{@link EmoticonGrid}的注释
     * 
     * @param listener
     */
    public void setOnEmoticonClickListener(onEmoticonClickListener listener) {
        mListener = listener;
    }

    /**
     * 设置表情View被Touch的监听。<br>
     * Click和Touch的区别，见{@link EmoticonGrid}的注释
     * 
     * @param listener
     */
    public void setOnEmoticonTouchListener(onEmoticonTouchListener listener) {
        mOnEmoticonTouchListener = listener;
    }
}
